package com.toubutu.audio.admin.controller;

import com.toubutu.anno.LoginRequired;
import com.toubutu.audio.admin.dto.AdminVideoTagQueryDto;
import com.toubutu.audio.admin.dto.VideoTagDto;
import com.toubutu.audio.common.PermissionCode;
import com.toubutu.audio.entity.VideoTag;
import com.toubutu.audio.service.VideoTagService;
import com.toubutu.audio.valid.ValidGroup;
import com.toubutu.common.PageUtils;
import com.toubutu.common.Result;
import com.toubutu.permission.Permission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 戒躁
 * @since 2024-01-10
 */
@RestController
@Api(tags = "后台视频标签接口")
@RequestMapping("/admin/tag")
@LoginRequired
public class AdminVideoTagController {
    @Resource
    private VideoTagService videoTagService;

    @PostMapping("/page/list")
    @ApiOperation("分页查询视频标签")
    @Permission(value = PermissionCode.Tag.TAG_LIST)
    public Result<PageUtils<VideoTag>> pageQueryTag(@RequestBody AdminVideoTagQueryDto dto){
        return Result.ok(videoTagService.pageQueryVideoTage(dto));
    }
    @GetMapping("/list/all")
    @ApiOperation("获取全部视频标签")
    public Result<List<VideoTag>> getAllTag(){
        return Result.ok(videoTagService.getAllTags());
    }

    @GetMapping("/info/{tagId}")
    @ApiOperation("获取标签信息")
    @Permission(value = PermissionCode.Tag.TAG_DETAIL)
    public Result<VideoTag> getTagInfo(@PathVariable Integer tagId){
        return Result.ok(videoTagService.getTagInfo(tagId));
    }

    @PostMapping("/add")
    @ApiOperation("添加标签")
    @Permission(value = PermissionCode.Tag.TAG_ADD)
    public Result<VideoTag> addTag(@RequestBody @Validated(value = ValidGroup.Add.class) VideoTagDto dto){
        videoTagService.addTag(dto);
        return  Result.ok();
    }
    @PostMapping("/update")
    @ApiOperation("修改标签")
    @Permission(value = PermissionCode.Tag.TAG_UPDATE)
    public Result<VideoTag> updateTag(@RequestBody @Validated(value = ValidGroup.Update.class) VideoTagDto dto){
        videoTagService.updateTag(dto);
        return  Result.ok();
    }
    @DeleteMapping("/delete/{tagId}")
    @ApiOperation("删除标签")
    @Permission(value = PermissionCode.Tag.TAG_DELETE)
    public Result<Void> deleteTag(@PathVariable Integer tagId){
        videoTagService.deleteTagById(tagId);
        return Result.ok();
    }
}
